<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .tab {
            width: 750px;
            margin: 0 auto;
            background-color: aquamarine;
        }

        .tab ul {
            display: flex;
            justify-content: center;
            align-items: center;
            /* width: 800px; */
            background-color: rgb(181, 177, 177);
        }

        li {
            list-style: none;
            text-align: center;
            height: 45px;
            line-height: 45px;
            flex: 1;
        }

        .style {
            background-color: brown;
        }

        .tab_item {
            width: 750px;
            height: 400px;
            background-color: aquamarine;
        }

        .tab_item img {
            /* display: block; */
            display: none;
            width: 100%;
            height: 100%;
        }

        /* .tab .tab_item img {
           
        } */

        #block {
            display: block; 
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab_h">
            <ul>
                <li class="style">胡歌</li>
                <li>彭于晏</li>
                <li>小乔</li>
                <li>西施</li>
                <li>李白</li>
            </ul>
        </div>
        <div class="tab_item">

            <img src="/pink/imgs/04.png" alt="" id="block">

            <img src="/pink/imgs/彭于晏.png" alt="">

            <img src="/pink/imgs/zyz_txt/1.png" alt="">

            <img src="/pink/imgs/zyz_txt/2.png" alt="">

            <img src="/pink/imgs/03.png" alt="">

        </div>
    </div>
    <script>
        var lis = document.querySelector('.tab_h').querySelectorAll('li')
        var  img=document.querySelector('.tab_item').querySelectorAll('img')
        console.log(img);
        for (let i = 0; i < lis.length; i++) {
            lis[i].setAttribute('index',i)
            lis[i].onclick = function () {
                for(i=0;i<lis.length;i++){
                    lis[i].className=''
                }
                this.className='style'
                 for(i =0;i<img.length;i++){
                    img[i].style.display='none' 
                 }
              let index= this.getAttribute('index') 
              console.log(index);
              img[index].style.display='block'
            }
        }

    </script>
</body>

</html>